<!DOCTYPE html>
<html lang="en">
<head>
    <meta charset="UTF-8">
    <title>文件转字符串下载</title>
    <!--<input type="text" id="fileName"/>-->
    <script src="https://code.jquery.com/jquery-3.1.1.min.js"></script>
</head>
<body>
    <button onclick="go()">down</button>
    <script type="application/javascript">
        function go() {
            var url = "/home/file";
            // if($('#fileName').val()){
            //    url = url + "/" + $('#fileName').val()
            // }
            $.ajax({
                url: url,
                success: function (data) {
                    console.log(data)
                    var raw = data;
                    var uInt8Array = new Uint8Array(raw.length / 8);
                    for (var i = 0; i < raw.length / 8; i++) {
                        uInt8Array[i] = getEightOf(data, i);
                    }
                        console.log(uInt8Array)
                        var blob = new Blob([uInt8Array], {type: "text/plain"});
                        console.log(blob)
                        var url = window.URL.createObjectURL(blob);
                        var a = document.createElement('a');
                        a.href = url;
                        a.download = 'test.txt';
                        a.click();
                    }
                })
            }

        function getEightOf(data,i) {
            var offset = i*8;
            console.log(data.substring(offset,offset+8))
            return parseInt(data.substring(offset,offset+8),2);
        }
    </script>
</body>
</html>